package com.cykj.controller;

import com.cykj.service.DepartmentService;
import com.cykj.util.ResponseDto;
import com.cykj.vo.ChangeShow;
import com.cykj.vo.ChangeStatusVo;
import com.cykj.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/depart")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/getInfo")
    public ResponseDto getInfoById(int id){
        ResponseDto dto = departmentService.getInfoById(id);
        return dto;
    }

    @RequestMapping("/getAllDepart")
    public ResponseDto getAllDepart(@RequestBody PageVo vo){
        ResponseDto infoById = departmentService.getAllDepart(vo.getPageCurr(), vo.getPageSize());
        return infoById;
    }
    @RequestMapping("/changeStatus")
    public ResponseDto changeStatus(@RequestBody ChangeStatusVo vo){
        if (vo.getProStatus() == 2){
            vo.setProStatus(0);
        }else if (vo.getProStatus() == 1){
            vo.setProStatus(1);
        }
        ResponseDto dto = departmentService.changeStatus(vo.getProStatus(), vo.getDepartId());
        return dto;
    }

    @RequestMapping("/changeShow")
    public ResponseDto changeShow(@RequestBody ChangeShow vo){
        if (vo.getProShow() == 2){
            vo.setProShow(0);
        }else if (vo.getProShow() == 1){
            vo.setProShow(1);
        }
        ResponseDto dto = departmentService.changeShow(vo.getProShow(), vo.getDepartId());
        return dto;
    }
    @RequestMapping("/searchDepartInfo")
    public ResponseDto searchDepartInfo( String value,int pageCurr,int pageSize){
        System.out.println("---------");
        System.out.println(value);
        return departmentService.searchDepartInfo(value,pageCurr, pageSize);
    }
    @RequestMapping("/alterDepart")
    public ResponseDto alterDepart(int departId,String departName,String departIntro){
        return departmentService.alterDepart(departId, departName, departIntro);
    }
    @RequestMapping("/deleteDepart")
    public ResponseDto deleteDepart(int departId){
        return departmentService.deleteDepart(departId);
    }

    @RequestMapping("/getAllDepartName")
    public ResponseDto getAllDepartName() {
        return departmentService.getAllDepartName();
    }

    @RequestMapping("/commitDelete")
    public ResponseDto commitDelete(String checkedDepart) {
        try {
            return departmentService.commitDelete(checkedDepart);
        } catch (Exception e) {
            return new ResponseDto(-1, "操作失败了", null);
        }
    }
    @RequestMapping("/selectDepartId")
    public ResponseDto selectDepartId(String fatherDepart){
        return departmentService.selectDepartId(fatherDepart);
    }
    @RequestMapping("/addDepartCommit")
    public ResponseDto addDepartCommit(String departName, int departmentParentId, String status, String show, String departInfo){
        return departmentService.addDepartCommit(departName, departmentParentId, status, show, departInfo);
    }
}
